#include <iostream>
#include <vector>
#include <climits>
using namespace std;

void Test1()
{
    string s;
    cin >> s;

    int res = INT_MAX;
    vector<int> v(26);

    for (const auto& e : s)
    {
        ++v[e - 'a'];
    }

    for (char ch = 'a'; ch <= 'z'; ++ch)
    {
        if (v[ch - 'a'] > 0)
        {
            int tmp = 0;
            for (const auto& e : s)
            {
                int count = abs(e - ch);
                tmp += min(count, 26 - count);
            }

            res = min(res, tmp);
        }
    }

    cout << res << endl;
}


int main()
{
    // Test1();




    return 0;
}